home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJLSR111.ZIP / libsrc / c / gen / getpwent.c < prev    next >
C/C++ Source or Header  |  1993-09-26  |  1KB  |  95 lines

  1. /*
  2.   (c) Copyright 1992 Eric Backus
  3.  
  4.   This software may be used freely so long as this copyright notice is
  5.   left intact.  There is no warrantee on this software.
  6. */
  7.  
  8. #include <pwd.h>
  9. #include <string.h>        /* For strcmp() */
  10. #include <stdlib.h>        /* For getenv(), getuid(), getgid() */
  11.  
  12. static struct passwd    pw;
  13. static int counter = 0;
  14.  
  15. static void
  16. fill_in()
  17. {
  18.     char    *p;
  19.  
  20.     pw.pw_name = getlogin();
  21.     pw.pw_passwd = "*";
  22.     pw.pw_uid = getuid();
  23.     pw.pw_gid = getgid();
  24.     pw.pw_age = "";
  25.     pw.pw_comment = "";
  26.     pw.pw_gecos = "DOS User";
  27.  
  28.     p = getenv("HOME");
  29.     if (p)
  30.     pw.pw_dir = p;
  31.     else
  32.     pw.pw_dir = "/";
  33.  
  34.     p = getenv("SHELL");
  35.     if (p)
  36.     pw.pw_shell = p;
  37.     else
  38.     pw.pw_shell = "/bin/sh";
  39.  
  40.     pw.pw_audid = -1;
  41.     pw.pw_audflg = -1;
  42. }
  43.  
  44. struct passwd *
  45. getpwent(void)
  46. {
  47.     if (counter == 0)
  48.     {
  49.     counter++;
  50.     fill_in();
  51.     return &pw;
  52.     }
  53.     return NULL;
  54. }
  55.  
  56. struct passwd *
  57. fgetpwent(FILE *f)
  58. {
  59.     if (counter == 0)
  60.     {
  61.     counter++;
  62.     fill_in();
  63.     return &pw;
  64.     }
  65.     return NULL;
  66. }
  67.  
  68. struct passwd *
  69. getpwuid(int uid)
  70. {
  71.     fill_in();
  72.     if (pw.pw_uid == uid) return &pw;
  73.     return NULL;
  74. }
  75.  
  76. struct passwd *
  77. getpwnam(char *name)
  78. {
  79.     fill_in();
  80.     if (strcmp(pw.pw_name, name) == 0) return &pw;
  81.     return NULL;
  82. }
  83.  
  84. void
  85. setpwent(void)
  86. {
  87.   counter = 0;
  88. }
  89.  
  90. void
  91. endpwent(void)
  92. {
  93.   counter = 0;
  94. }
  95.